package com.zian.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum GoodsSellStatusEnum {

    SELLING(0, "在售"),

    STOP_SELLING(1, "已下架");

    @EnumValue // 枚举值存储到数据库中
    @JsonValue // 枚举值序列化到json中
    private final Integer code;
    private final String desc;

    GoodsSellStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static GoodsSellStatusEnum getGoodsSellStatusEnumByCode(Integer code) {
        for (GoodsSellStatusEnum goodsSellStatusEnum : GoodsSellStatusEnum.values()) {
            if (goodsSellStatusEnum.getCode().equals(code)) {
                return goodsSellStatusEnum;
            }
        }
        return null;
    }

    public static boolean isSelling(Integer code) {
        return SELLING.getCode().equals(code);
    }
}
